<template>
	<view class="flower-content">
		<!-- 顶部自定义导航 -->
		<tn-nav-bar fixed alpha customBack>
			<view slot="back" class='tn-custom-nav-bar__back' @click="goBack">
				<text class='icon tn-icon-left'></text>
				<text class='icon tn-icon-home-capsule-fill'></text>
			</view>
		</tn-nav-bar>

		<swiper class="card-swiper" :circular="true" :autoplay="true" duration="500" interval="5000"
			@change="cardSwiper">
			<swiper-item v-for="(item,index) in swiperList" :key="index" :class="cardCur==index?'cur':''">
				<view class="swiper-item image-banner">
					<image :src="item.url" mode="aspectFill" v-if="item.type=='image'"></image>
				</view>
			</swiper-item>
		</swiper>


		<view class="top-wrap tn-padding-top-xs">

			<view class="tn-padding tn-padding-bottom-sm"
				style="background-color: #FFFFFF;border-radius: 24rpx;margin: 30rpx 30rpx 30rpx 30rpx;position: relative;">
				<view class="tn-flex tn-flex-row-between tn-flex-col-center">
					<view class="justify-content-item tn-text-bold tn-text-xl tn-flex-basic-xl">
						{{roominfo.roomNumber}}
					</view>

				</view>



				<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-top-sm">
					<view class="justify-content-item tn-color-orange" style="font-size: 52rpx;">
						<text class="tn-text-bold">{{roominfo.rent}}</text>
						<text class="tn-margin-left-xs tn-text-xs tn-color-gray--dark">元</text>
					</view>

				</view>

			</view>

			<view class="tn-padding"
				style="background-color: #FFFFFF;border-radius: 24rpx;margin: 30rpx 30rpx 30rpx 30rpx;position: relative;">
				<view class="tn-flex tn-flex-row-between tn-flex-col-center">
					<view class="justify-content-item" style="color: #E83A37;">
						<text class="tn-color-gray--dark tn-padding-right-xs">水卡：</text>
						<text class="tn-text-xl tn-text-bold">{{roominfo.waterCard}}</text>
					</view>
				</view>
				<view class="tn-flex tn-flex-row-between tn-flex-col-center">
					<view class="justify-content-item" style="color: #E83A37;">
						<text class="tn-color-gray--dark tn-padding-right-xs">电卡：</text>
						<text class="tn-text-xl tn-text-bold">{{roominfo.electricityCard}}</text>
					</view>
				</view>
				<view class="tn-flex tn-flex-row-between tn-flex-col-center">
					<view class="justify-content-item" style="color: #E83A37;">
						<text class="tn-color-gray--dark tn-padding-right-xs">气卡：</text>
						<text class="tn-text-xl tn-text-bold">{{roominfo.gasCard}}</text>
					</view>
				</view>
			</view>
			<view class="tn-footerfixed">
				<view class="tn-flex tn-flex-row-between tn-flex-col-center tn-padding-xs">

					<view class="tn-flex-2 justify-content-item tn-padding-top-xs tn-padding-bottom-xs">
						<view class="tn-flex tn-flex-row-between">
							<view class="tn-flex-1 justify-content-item tn-margin-xs tn-text-center">
								<tn-button shape="round" backgroundColor="#E83A37" padding="35rpx 0" width="90%"
									:fontSize="30" shadow @click="copyCardsInfo">
									<text class="tn-color-white">复制水电气卡号</text>
								</tn-button>
							</view>

						</view>
					</view>
				</view>
			</view>


		</view>


	</view>
</template>

<script>
	import template_page_mixin from '@/libs/mixin/template_page_mixin.js'
	export default {

		name: 'TemplateDetails',
		mixins: [template_page_mixin],
		data() {
			return {
				cardCur: 0,
				swiperList: [],
				roominfo: {
					roomId: null, // 如果roomId是必须的，这里应赋一个合适的默认值或者留空
					propertyId: null, // 如果propertyId是必须的，这里应赋一个合适的默认值或者留空
					propertyName: "未提供", // 提供一个默认值或说明
					createdAt: "未提供", // 提供一个默认值或说明
					roomNumber: "6-13",
					roomType: "未提供", // 提供一个默认值或说明
					rentalType: "未提供", // 提供一个默认值或说明
					photo: null, // 如果photo是必须的，这里应赋一个合适的默认值或者留空
					rent: 0, // 假设租金默认为0，或者留空
					deposit: 0, // 假设押金默认为0，或者留空
					electricityPrice: 0, // 假设电费单价默认为0，或者留空
					electricityCard: null, // 如果electricityCard是必须的，这里应赋一个合适的默认值或者留空
					waterPrice: 0, // 假设水费单价默认为0，或者留空
					waterCard: null, // 如果waterCard是必须的，这里应赋一个合适的默认值或者留空
					gasPrice: 0, // 假设煤气费单价默认为0，或者留空
					gasCard: null, // 如果gasCard是必须的，这里应赋一个合适的默认值或者留空
					numberOfResidents: 0 // 假设居民数量默认为0，或者留空
				}

			}
		},
		onLoad(options) {
			console.log("ssssssssss", options.res)


			if (options.res) {
				const res = JSON.parse(decodeURIComponent(options.res));
				console.log(res); // 打印出传递的res对象

				this.roominfo = res

				// 根据roominfo.photo动态设置swiperList
				if (this.roominfo.photo) {
					this.swiperList = [{
						url: this.roominfo.photo,
						type: 'image'
					}];
				}
			}

		},
		methods: {
			copyCardsInfo() {
				// 构建要复制的内容
				const cardsInfo =
					`水卡：${this.roominfo.waterCard}\n电卡：${this.roominfo.electricityCard}\n气卡：${this.roominfo.gasCard}`;
				// 调用uni的API来复制内容到剪切板
				uni.setClipboardData({
					data: cardsInfo,
					success: function() {
						uni.showToast({
							title: '复制成功',
							icon: 'success'
						});
					},
					fail: function() {
						uni.showToast({
							title: '复制失败',
							icon: 'none'
						});
					}
				});
			},
			// cardSwiper
			cardSwiper(e) {
				this.cardCur = e.detail.current
			},
			// 跳转
			tn(e) {
				uni.navigateTo({
					url: e,
				});
			},
		}
	}
</script>

<style lang="scss" scoped>
	/* 胶囊*/
	.tn-custom-nav-bar__back {
		width: 100%;
		height: 100%;
		position: relative;
		display: flex;
		justify-content: space-evenly;
		align-items: center;
		box-sizing: border-box;
		background-color: rgba(0, 0, 0, 0.15);
		border-radius: 1000rpx;
		border: 1rpx solid rgba(255, 255, 255, 0.5);
		color: #FFFFFF;
		font-size: 18px;

		.icon {
			display: block;
			flex: 1;
			margin: auto;
			text-align: center;
		}

		&:before {
			content: " ";
			width: 1rpx;
			height: 110%;
			position: absolute;
			top: 22.5%;
			left: 0;
			right: 0;
			margin: auto;
			transform: scale(0.5);
			transform-origin: 0 0;
			pointer-events: none;
			box-sizing: border-box;
			opacity: 0.7;
			background-color: #FFFFFF;
		}
	}

	.flower-content {
		background-color: #F8F7F8;
		min-height: 100vh;
		padding-bottom: 60rpx;
		padding-bottom: calc(80rpx + env(safe-area-inset-bottom) / 2);
		padding-bottom: calc(80rpx + constant(safe-area-inset-bottom));
	}

	/* 内容 */
	.top-wrap {
		position: relative;
		z-index: 1;
		// padding: 20rpx 30rpx;
		border-radius: 60rpx 60rpx 0 0;
	}



	/* 底部安全边距 start*/
	.tn-tabbar-height {
		background-color: #F9F9F9;
		min-height: 120rpx;
		height: calc(140rpx + env(safe-area-inset-bottom) / 2);
		height: calc(140rpx + constant(safe-area-inset-bottom));
	}


	/* 轮播视觉差 start */
	.card-swiper {
		height: 750rpx !important;
	}

	.card-swiper swiper-item {
		width: 750rpx !important;
		left: 0rpx;
		box-sizing: border-box;
		// padding: 0rpx 30rpx 90rpx 30rpx;
		overflow: initial;
	}

	.card-swiper swiper-item .swiper-item {
		width: 100%;
		display: block;
		height: 100%;
		transform: scale(1);
		transition: all 0.2s ease-in 0s;
		overflow: hidden;
	}

	.card-swiper swiper-item.cur .swiper-item {
		transform: none;
		transition: all 0.2s ease-in 0s;
	}

	.image-banner {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.image-banner image {
		width: 100%;
		height: 100%;
	}

	/* 轮播指示点 start*/
	.indication {
		max-width: 640px;
		margin: 0 auto;
		z-index: 9999;
		width: 100%;
		height: 36rpx;
		position: absolute;
		display: flex;
		flex-direction: row;
		align-items: center;
		justify-content: center;
	}

	.spot {
		background-color: #FFFFFF;
		opacity: 0.6;
		width: 10rpx;
		height: 10rpx;
		border-radius: 20rpx;
		top: -60rpx;
		margin: 0 8rpx !important;
		position: relative;
	}

	.spot.active {
		opacity: 1;
		width: 30rpx;
		background-color: #FFFFFF;
	}


	/* 底部*/
	.tn-footerfixed {
		position: fixed;
		background-color: #FFFFFF;
		box-shadow: 0rpx 0rpx 80rpx 0rpx rgba(0, 0, 0, 0.05);
		bottom: 0;
		padding-bottom: calc(env(safe-area-inset-bottom) / 2);
		width: 100%;
		transition: all 0.25s ease-out;
		will-change: transform;
		z-index: 100;
	}
</style>